import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


public class HashSetExam {
	
	public void mainmethodint(){
		Set<Integer> hs1=new HashSet<Integer>();
		Set<Integer> hs2=new HashSet<Integer>();
		
		//Adding value
		hs1.add(10);
		hs1.add(20);
		hs1.add(60);
		hs1.add(50);
		hs1.add(100);
		
		hs2.add(10);
		hs2.add(20);
		
		
		//displaying value
		System.out.println("Displaying HashSet:"+hs1);
		//Iterating value
		for(Integer i:hs1)
		{
			System.out.println("Iterating Hash set value:"+i);
		}
		//size of the HashSet
		System.out.println("Size of the HashSet:"+hs1.size());
		
		//check any value inside the set
		System.out.println("check any value inside the set:"+hs1.isEmpty());
		//check one value inside the set
		System.out.println("check one value inside the set:"+hs1.contains(10));
		//remove value
		System.out.println("Remove the value inside the set:"+ hs1.remove(100)+hs1);
		//containsall example
		System.out.println("containsall example:"+hs1.containsAll(hs2));
		//addall example
		Set<Integer> hs3=new HashSet<Integer>();
		hs3.add(400);
		hs3.add(500);
		System.out.println("addall example:"+hs1.addAll(hs3)+":"+hs1);
		//Removeall example
		Set<Integer> hs4=new HashSet<Integer>();
		hs4.add(400);
		hs4.add(500);
		System.out.println("removeall example:"+ hs1.removeAll(hs4)+":"+hs1 );
		//RetainAll example
		Set<Integer> hs5=new HashSet<Integer>();
		hs5.add(10);
		hs5.add(20);
		System.out.println("Retain All example:"+hs1.retainAll(hs5)+":"+hs1);
		
		//convert set into list
		List<Integer> al1=new ArrayList<Integer>(hs1);
		System.out.println("Convert set into list:"+al1);
	
	}
	
	public void mainmethodstr(){
		Set<String> hsuniques=new HashSet<String>();
		Set<String> hsdup=new HashSet<String>();
		
		
		
		String[] s={"one","two","three","four","five","one","five"};
		
		for(String s1:s){
			if(!hsuniques.add(s1))
				hsdup.add(s1);
		}
		System.out.println("Uniques HashSet value:"+hsuniques);
		System.out.println("Duplicate HashSet value:"+hsdup);
		}
	
	
	public static void main(String[] args) {
		
		HashSetExam hse=new HashSetExam();
		hse.mainmethodint();
		hse.mainmethodstr();
		
	}

}
